<?php

require_once ('log4php/Logger.php');
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ShiftClassifier
 *
 * @author LBerrocal
 */
class ShiftClassifier {
    private $logger;

    const SHIFT_TYPE_DAY ="DIURNO";
    const SHIFT_TYPE_NIGHT ="NOCTURNO";
    const SHIFT_TYPE_MIXED ="MIXTO";
    const SHIFT_TYPE_INVALID ="INVALIDO";

    private $dayShift;
    private $nightShift;
    private $maxDayShiftHours=8;
    private $maxNightShiftHours=7;
    private $maxMixedShiftHours=7.5;

    private $shiftCalculator;

    public function __construct(){
        $this->logger = Logger::getLogger('ShiftClassifier');

        $this->shiftCalculator = new ShiftCalculator();
        $this->dayShift ="06:00-18:00";
        $this->nightShift ="18:00-06:00";
    }

    public function classify(array $shifts){
        $dists = array();
        $i=0;
        $before=0.0;
        $inside=0.0;
        $after=0.0;

        //$sc = new ShiftCalculator();
        foreach ($shifts as $shift) {
            $dists[$i] = $this->shiftCalculator->distributeHours($this->dayShift,$shift);
            $before += $dists[$i]['before'];
            $inside += $dists[$i]['inside'];
            $after += $dists[$i]['after'];

             $this->logger->debug("Shift $i : " . $shift);
             $this->logger->debug("Distibution: Before: ".$dists[$i]['before']);
             $this->logger->debug("Distibution: Before: ".$dists[$i]['inside']);
             $this->logger->debug("Distibution: Before: ".$dists[$i]['after']);
             $i++;
        }
        $outside = $after + $before;
        $total = $outside + $inside;

        if($outside ==0){
            //day
            if($total <= $this->maxDayShiftHours){
                return ShiftClassifier::SHIFT_TYPE_DAY;
            }else{
                return ShiftClassifier::SHIFT_TYPE_INVALID;
            }
        }  elseif ($outside >= 3) {
            //night
            if($total <= $this->maxNightShiftHours){
                return ShiftClassifier::SHIFT_TYPE_NIGHT;
            }else{
                return ShiftClassifier::SHIFT_TYPE_INVALID;
            }
        }else{
            //mixed
            if($total <= $this->maxMixedShiftHours){
                return ShiftClassifier::SHIFT_TYPE_MIXED;
            }else{
                return ShiftClassifier::SHIFT_TYPE_INVALID;
            }
        }
    }

}
?>
